<html>
    <head>
        <link rel="stylesheet" type="text/css" href="css/style.css" />
    </head>
    <body class="center_content">
        <?php
        require_once("conn.php");

        $sql = "SELECT DISTINCT year FROM t_pack ORDER BY year DESC";
        $db = new DBC();
        $data = $db->fetchData($sql);
        ?>
        <label>年份选择
            <select name="year_month">
                <?php foreach ($data as $year) { ?>
                    <option><?php echo $year['year']; ?></option>
                <?php } ?>
            </select>
        </label>
        <p></p>
        
        <table width="800">
            <tr>
                <td width="200">年龄/月份</td>
                <?php
                for ($i = 0; $i < 12; $i++) {
                    ?>
                    <td width="50"><?php echo ($i + 1); ?>月</td>
                <?php } ?>

            </tr>
            <?php
            $sql = "SELECT year FROM t_pack ORDER BY year DESC LIMIT 0,1";
            $data = $db->fetchData($sql);
            if (count($data) > 0) {
                $lastYear = $data[0]['year'];

                $sql = "SELECT * FROM t_pack WHERE year = " . $lastYear . " ORDER BY month,age";
                $data = $db->fetchData($sql);
                $array = array();
                foreach ($data as $pack) {
                    $array[$pack['age']][$pack['month'] - 1] = $pack;
                }
                for ($i = 0; $i < 7; $i++) {
                    ?>
                    <tr>
                        <td height="50"><?php echo $i; ?>岁</td>
                        <?php
                        for ($j = 0; $j < 12; $j++) {
                            $obj = $array[$i][$j];
                            ?>
                            <td><?php if ($array[$i][$j]['imageURL'] != "") { ?><a href="packList.php?year=<?php echo $obj['year']; ?>&month=<?php echo $obj['month']; ?>&&age=<?php echo $obj['age']; ?>"><img src="<?php echo $array[$i][$j]['imageURL']; ?>" width="50" height="50" border="0" title="<?php echo $array[$i][$j]['name']; ?>"></a><?php } else { ?>&nbsp;<?php } ?></td>
                        <?php } ?>
                    </tr>
                <?php
                }
            }
            ?>  
        </table>

    </body>
</html>
